﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ComLib.ComFun;
using System.Xml.Serialization;
using ComLib.ConfigService;

namespace KAImage.Config
{
    public enum ImageMegreMode : int
    {
        Screen = 0,             // 滤色合成
        Multiply = 1,           // 正片叠底合成
        Both = 2,               // 综合合成
    }

    /// <summary>
    /// 图像合成选项
    /// </summary>
    [Serializable]
    [XmlRootAttribute("ImageMegreOption", Namespace = "KAImage.Config", IsNullable = false)]
    public class ImageMegreOption : XmlSerializeBase
    {      
        private ImageMegreMode _megreMode = ImageMegreMode.Screen;
        public ImageMegreMode MegreMode
        {
            get { return _megreMode; }
            set { _megreMode = value; }
        }

        private int _opacityScreen = 0;
        public int OpacityScreen
        {
            get { return _opacityScreen; }
            set { _opacityScreen = value; }
        }

        private int _opacityMultiply = 0;
        public int OpacityMultiply
        {
            get { return _opacityMultiply; }
            set { _opacityMultiply = value; }
        }

        /// <summary>
        /// 指示选项是否是默认值，一般对于不是默认值才进行调整
        /// </summary>
        public bool IsDefault
        {
            get
            {
                return _opacityMultiply == 0 && _opacityScreen == 0;
            }
        }
        public override bool Serialize()
        {
            return Serializer.SaveToXml(ConfigFilePath, this);
        }

        public override bool Load()
        {
            ImageMegreOption obj = (ImageMegreOption)Serializer.LoadFromXml(ConfigFilePath, this.GetType());
            if (obj != null)
            {
                this._megreMode = obj._megreMode;
                this._opacityScreen = obj._opacityScreen;
                this._opacityMultiply = obj._opacityMultiply;    
                this._nVer = obj._nVer;
                return true;
            }
            else
            {
                ErrorMessage = Serializer.Message;
                return false;
            }
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("图像合成选项: ");
            FillFieldValueStringDelegate FillString =
                (string field, object val) =>
                {
                    if (val != null)
                    {
                        builder.Append("[");
                        builder.Append(field);
                        builder.Append("]: ");
                        builder.Append(val.ToString() + "; ");
                    }
                };
            FillString("混合模式", _megreMode);
            FillString("滤色混合不透明度", _opacityScreen);
            FillString("正片叠底不透明度", _opacityMultiply);
            return builder.ToString();
        }
    }
}
